package doudizhu;
/*
 * 需求：斗地主发洗牌并对牌进行排序   （斗地主最小值为3）
 * **/
import java.util.HashMap;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.Collections;
public class Faxipai {
public static void main (String []args) {
	//创建HashMap集合
	HashMap<Integer,String> hm=new HashMap<Integer,String>();
	//创建ArrayList集合
	ArrayList<Integer> array=new ArrayList<Integer>();
	//创建花色和数字的数组
	String[]colors= {"♥","♠","♣","♦"};
	String[]numbers= {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
	//从0开始编号存入HashMap,并存入对应的牌，同时往ArrayList里面存入编号
    int index=0;
    for(String number:numbers) {
    	for(String color:colors) {
    		String puker=color.concat(number);
    		hm.put(index, puker);
    		array.add(index);
    		index++;
    	}
    }
    hm.put(index, "小王");
    array.add(index);
    index++;
    hm.put(index, "大王");
    array.add(index);
    //洗牌（此时洗的相当于是是编号）
    Collections.shuffle(array);
    //发牌  （发的也是编号，为了保证编号是排序的，创建TreeSet集合接受
    TreeSet<Integer> player1=new TreeSet<Integer>();
    TreeSet<Integer> player2=new TreeSet<Integer>();
    TreeSet<Integer> player3=new TreeSet<Integer>();
    TreeSet<Integer> dipai=new TreeSet<Integer>();
    for(int x=0;x<array.size();x++) {
    	if(x>=array.size()-3) {
    		dipai.add(array.get(x));
    	}else if(x%3==0) {
    		player1.add(array.get(x));
    	}else if(x%3==1) {
    		player2.add(array.get(x));
    	}else if(x%3==2) {
    		player3.add(array.get(x));
    	}
    }
    //看牌
    Lookpai("张欣",player1,hm);
    Lookpai("孙晓",player2,hm);
    Lookpai("赵喜艳",player3,hm);
    Lookpai("底牌",dipai,hm);
    
}
public static void Lookpai(String name,TreeSet<Integer>st,HashMap<Integer,String> hm) {
	System.out.print(name+"的牌");
	for(Integer key:st) {
		String value=hm.get(key);
		System.out.print(value+" ");
	}
	System.out.println();
}
}
